// cloudfunctions/getUserOpenId/index.js
const cloud = require('wx-server-sdk')

cloud.init({
  env: 'cloud1-3gew2xhnadfbd1bd'
})

/**
 * 获取用户 openId 云函数
 * 用于客户端获取 openId（用于命名上传的头像文件）
 */
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  
  return {
    success: true,
    openId: wxContext.OPENID
  }
}
